package org.ahuanlien.crm.service.impl;

import org.ahuanlien.crm.domain.Salary;
import org.ahuanlien.crm.mapper.SalaryMapper;
import org.ahuanlien.crm.query.StaffManagementQueryObject;
import org.ahuanlien.crm.service.ISalaryService;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class SalaryServiceImpl implements ISalaryService{

    @Autowired
    SalaryMapper salaryMapper;

    @Override
    public void deleteByPrimaryKey(Long id) {
        salaryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(Salary record) {
        if (record.getId() != null) {
            salaryMapper.updateByPrimaryKey(record);
        } else {
            salaryMapper.insert(record);
        }
    }

    @Override
    public Salary selectByPrimaryKey(Long id) {
        return salaryMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Salary> selectAll() {
        return salaryMapper.selectAll();
    }
    @Override
    public PageResult query(StaffManagementQueryObject qo) {
        int count = salaryMapper.query4Count(qo);
        if (count == 0) {
            return new PageResult(count, Collections.EMPTY_LIST);
        }
        List<Salary> result = salaryMapper.query4List(qo);
        return new PageResult(count, result);
    }

}
